This action allows you to easily upload a photo or video to your app. You have the flexibility to store the file on Firebase, Supabase storage, or your own server using an API. Once uploaded, you can access the file through its generated URL. This URL can be used to display the content immediately or store it in a database for future retrieval.
Prerequisites for FirebaseFirebase should be connected to your project. Follow the instructions on this page for integrating Firebase with FlutterFlow.Firebase Authentication must be properly configured. Check out this page for setting up authentication.Firebase Storage must be set up and properly configured. It takes just a second! Follow the instructions on this page.At least one Firebase Collection should be configured for the project so that you can store the generated URL.Prerequisites for SupabaseMake sure to integrate Supabase into your app.Create a storage bucket in Supabase.Tip: To let anyone download the uploaded media, you can enable the 'Public bucket.'Apply additional security rules which determine who can access the bucket. Tip: If you are uploading to a folder structure like this 'pics/uploads,' here is how you can add a policy that allows only authenticated users to upload their profile picture.Adding Upload/Save Media actionFollow the steps below to add this action to any widget.
Select the Widget (e.g., Button) on which you want to add the action.Select Actions from the Properties Panel (the right menu), and click Open. This will open an Action Flow Editor in a new popup window. If it's the first action, click + Add Action button. Otherwise, click the "+" button below the previous action tile and select Add Action.Search and select the Upload/Save Media (under Utilities > Upload Data) action.If you haven't integrated Firebase or Supabase yet, the default upload type will be Store media for upload. However, once integrated, you can choose the Upload Type as Firebase, Supabase or Local (Widget State).Use the Media Type/Source to specify whether you want to upload a photo or a video, or both using this action.Using Media Source dropdown, you can choose between Camera, Gallery, and Either Camera or Gallery (this option will bring up a bottom sheet from where the user can choose the media source as Camera or Gallery) and Uploaded Media. If you choose Uploaded Media, ensure you add one more same action (before this action) with Upload Type set to Local Upload (Widget State).If you are uploading a photo, you can set a maximum width and height for it by using the Max Width and Max Height properties, respectively. This will modify the image dimension by maintaining the photo's aspect ratio.You can control the Image Quality by using the slider or directly entering the value. The value must be 0 to 100, where 100 is the original quality.To retrieve the uploaded media's dimensions, i.e., width and height, enable Include Media Dimension. This computation is expensive, so be sure before you enable it.Use the Source Picker Style to tailor the appearance of the bottom sheet UI that opens when selecting either Camera or Gallery.You can Allow multiple images. Note that for this to work, the Media Source must be set to only Gallery. After the multiple images are uploaded, you can access them via Set from Variable menu > Widget State > Uploaded File URLs (List ).To let users know whether the image is still uploading, you can enable the Show Snack bar.If you selected Either Camera or Gallery, you would be presented with a few more properties to define the Source Picker Style (the bottom sheet design). You can specify the Font Family, Text Color, and Background Color of the bottom sheet.In Upload Type:If you selected Firebase, you must deploy the storage rules.If you selected Supabase, provide the Bucket Name and set the Uploaded Folder Path (e.g., pics/uploaded). This is the path where the media will be uploaded.if you selected Local (Widget State), you probably want to upload the media to your backend server via API. To do so, add the next action as an API call and select the API that will upload the file to your server. Note that the request body for this API must be in Multipart format. See how to configure an API for the multipart request body. Tip: When this type is selected, you have an option to directly display the image before it gets uploaded to your server; see here.Once you have uploaded the media, see how to display it on a widget in the next section.Upload to FirebaseUpload to SupabaseUpload media via APIShowing uploaded mediaFor displaying the media on the same page from where the Upload/Save Media Action is called, follow the steps below:
Drag and drop the appropriate widget that can display the uploaded media. For example, to display uploaded photo, you can use the Image widget. Similarly, for video, use the VideoPlayer widget.Move to the properties panel, set its Type to Network, and click Set from Variable.For media uploaded on Firebase or Supabase, select the Source as Widget State > Uploaded File URL.For media uploaded via API, select the Source as Action Outputs > [Action Output Variable Name] (Api Response). This should be the response of the API that was used to upload the media, and it must contain the URL of the uploaded media. To retrieve the URL from API response, see how to use JSON path.To show the placeholder image/video until the current one is uploaded, click the Set from Variable and specify a placeholder image/video URL under the Default Value property.Click on Confirm.tipTo ensure smooth functionality, it's important to provide a Default Value when displaying media on the same page as the upload action. Without it, you may encounter errors during app runtime due to an initially empty URL. Once this action is triggered and the media is successfully stored on Firebase/Supabase Storage, the URL becomes accessible.
Showing media uploaded on Firebase/SupabaseShowing media uploaded via APIDisplay images from bytes (in memory/not yet uploaded)If you simply wish to display an image within your app without uploading it anywhere, or if you'd like to preview the image before sending it to your server through an API, you can achieve this by configuring the Image Type as Uploaded File and specifying the Uploaded File source as Widget State -> Uploaded Local File.
Storing the uploaded media URLYou should store the uploaded media URL in your database (Firebase collection or database table) so that you can easily access it later inside the app.
Save URL in Firebase collectionTo save URL in a Firebase collection:
Ensure you have a field that can store a photo or video path, for example, photo_url (Data Type: Image Path) or video_url (Data Type: Video Path).Now use the Firebase Create/Update document action to store the URL in a field.noteWhile choosing Value Source, you can set either Widget State > Uploaded File URL or directly choose Uploaded Photo/Video.
Saving uploaded URL in Firestore documentSaving uploaded URL in Firestore documentSaving uploaded URL in Firestore documentSave URL via backend APIYou can use your backend AP to store the URL, like you would do for any other data.
Adding BlurHashBlurHash is a new and innovative way of generating image placeholders that are both compact and visually appealing. When you're scrolling through a web or mobile app, you may have noticed that some images take longer to load. This can be frustrating and disrupt the user experience. That's where BlurHash comes in - it provides a way to display a blurred version of the image that looks similar to the original while the real image is loading in the background.
With BlurHash, you can create more visually appealing and contextually relevant placeholders that better reflect the content of the image being loaded. It can be used in a variety of contexts, from photo galleries and social media apps to e-commerce and news apps.
Here's how it looks when images are loaded with BlurHash:
Using BlurHash to display cat imagesHere are the steps to generate and use the BlurHash:
Generate BlurHashSave BlurHashUse BlurHashGenerate BlurHashThere is no separate action to generate the Blurhash. Instead, you can generate it using the Upload/Save Media action. From the page where you upload the image, use this action and simply enable the Include Blur Hash option. This will automatically create a Blurhash for the image being uploaded.
Save BlurHashThe generated BlurHash is accessible via the Widget State > Uploaded Local File > Media Blur Hash. Before you use the BlurHash, It is recommended to store it in the same collection or table where you save the image URL for convenient access.
Collection schema to store BlurHashHere's how you access and save the BlurHash in a Firebase collection using create document action:
tipYou can also create a custom data type called 'image' and then add two fields such as 'image_url' and 'image_blurhash' like this:
Custom data type to store image URL and BlurHashUse BlurHashTo use BlurHash, select the Image widget, move to the properties panel, enable the Use Blur Hash option, and then set the Blur Hash String value from a variable.